<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Returning Outcome types from Coroutines - Boost.Outcome documentation</title>
<link rel="stylesheet" href="../../../css/boost.css" type="text/css">
<meta name="generator" content="Hugo 0.52 with Boostdoc theme">
<meta name="viewport" content="width=device-width,initial-scale=1.0"/>

<link rel="icon" href="../../../images/favicon.ico" type="image/ico"/>
<body><div class="spirit-nav">
<a accesskey="p" href="../../../tutorial/essential/coroutines/awaitables.html"><img src="../../../images/prev.png" alt="Prev"></a>
    <a accesskey="u" href="../../../tutorial/essential/coroutines.html"><img src="../../../images/up.png" alt="Up"></a>
    <a accesskey="h" href="../../../index.html"><img src="../../../images/home.png" alt="Home"></a><a accesskey="n" href="../../../tutorial/essential/coroutines/co_await.html"><img src="../../../images/next.png" alt="Next"></a></div><div id="content">
  <div class="titlepage"><div><div><h1 style="clear: both">Returning Outcome types from Coroutines</h1></div></div></div>
  <p><code>eager&lt;T&gt;</code> and <code>lazy&lt;T&gt;</code> and their atomic editions are completely standard
awaitables with no special behaviours, <strong>except</strong> if <code>T</code> is a <code>basic_result</code>
or <code>basic_outcome</code>. In that situation, the following occurs:</p>

<p>If the Coroutine throws a C++ exception which was not handled inside the Coroutine
body, Outcome&rsquo;s awaitable types try to convert it into a form which your Result or
Outcome type being returned can transport. For example:</p>

<ul>
<li><p>If your Coroutine were returning a <code>result&lt;T, std::exception_ptr&gt;</code>, an
errored Result with a pointer to the exception thrown would be returned.</p></li>

<li><p>If your Coroutine were returning a <code>result&lt;T, std::error_code&gt;</code>, the
exception ptr is passed to <a href="../../../reference/functions/error_from_exception.html" class="api-reference"><code>error_from_exception(</code></a>
<code>)</code> to see
if it can be matched to an equivalent <code>std::error_code</code>. If it can, an
errored Result with the equivalent error code would be returned.</p></li>

<li><p>If your Coroutine were returning an <code>outcome&lt;T, std::error_code, std::exception_ptr&gt;</code>,
an Errored Outcome is chosen preferentially to an Excepted Outcome.</p></li>

<li><p>If your Coroutine were returning an <code>experimental::status_result&lt;T, system_code&gt;</code>,
because Experimental SG14 <code>system_code</code> can transport error codes or
exception ptrs (or indeed <code>std::error_code</code>&rsquo;s), an errored Result
is returned.</p></li>
</ul>


        </div><p><small>Last revised: April 07, 2020 at 10:22:38 &#43;0100</small></p>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../../../tutorial/essential/coroutines/awaitables.html"><img src="../../../images/prev.png" alt="Prev"></a>
    <a accesskey="u" href="../../../tutorial/essential/coroutines.html"><img src="../../../images/up.png" alt="Up"></a>
    <a accesskey="h" href="../../../index.html"><img src="../../../images/home.png" alt="Home"></a><a accesskey="n" href="../../../tutorial/essential/coroutines/co_await.html"><img src="../../../images/next.png" alt="Next"></a></div></body>
</html>
